package com.yunshipei.ui.view.client;

import android.content.Intent;
import android.net.Uri;
import android.net.http.SslError;
import android.webkit.SslErrorHandler;
import android.webkit.WebView;
import android.webkit.WebViewClient;

import com.yunshipei.utils.YspProtocolUtils;

public class H5WebViewClient extends WebViewClient {

    @Override
    public boolean shouldOverrideUrlLoading(WebView view, String url) {
        if (url.startsWith("tel:")) {
            Intent intent = new Intent(Intent.ACTION_DIAL, Uri.parse(url));
            view.getContext().startActivity(intent);
            return true;
        }
        if (url.startsWith("mailto:")) {
            YspProtocolUtils.openEmailClient(view.getContext(), url);
            return true;
        }
        view.loadUrl(url);
        return false;
    }

    @Override
    public void onReceivedSslError(WebView view, SslErrorHandler handler, SslError error) {
        handler.proceed();
    }
}
